
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for view_group_profile.
	''' </summary>
	Public Partial Class view_group_profile
		Inherits BaseWebPage
		Protected litMembersCount As System.Web.UI.WebControls.Literal
		Protected txtStartIndexHidden As System.Web.UI.WebControls.TextBox
		Protected txtMembersCountHidden As System.Web.UI.WebControls.TextBox
		Protected Linkbutton1 As System.Web.UI.WebControls.LinkButton
		Public blankImagesCount As Integer = 0
		Protected imgEditMember As System.Web.UI.WebControls.Image
		Protected dgGroupEvents As System.Web.UI.WebControls.DataGrid
		Protected lblEvents As System.Web.UI.WebControls.Label
		Protected grpID As Integer = -1
		Protected grpEvents As ArrayList = Nothing
		Protected htPageConstants As New Hashtable()

		Public Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)
			' this.pageTemplate.PageTitle = PageTitles.VIEW_MY_PROFILE_PAGE;

			Dim usr As User = LoggedUser
			If usr = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If

			If Constants.SHOW_GROUPS <> Constants.SHOW_ON Then
				Throw New Exception(Constants.ERROR_MESSAGE_NO_ACCESS)
			End If

			Try
				grpID = Convert.ToInt32(Request.Params(Constants.GROUP_PARAM))
				Response.Redirect(String.Format("{0}?{1}={2}", Constants.GROUP, Constants.GROUP_PARAM, grpID))
			Catch
				Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
			End Try
			Dim grp As Group = Groups.GetGroupByID(grpID)

			' the group doesn't exist
			If grp = Nothing Then
				Throw New Exception(Constants.ERROR_MESSAGE_GROUP_DOESNT_EXIST_ERROR)
			End If

			If grp.Uid <> usr.ID Then
				Response.Redirect(Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID)
			End If

			Me.initPageTitles(Constants.VIEW_GROUP_PROFILE, "", Form1, Nothing, htPageConstants)
			Me.initAdvertisements(Form1, Nothing)

			' set group name
			litGroupName.Text = grp.Name
			litGroupName1.Text = grp.Name
			litGroupName2.Text = grp.Name

			' set About Group
			lblAboutGroup.Text = grp.About
			lblAbout.Text = (Me.GetPageConstText(htPageConstants, "CONST_About_TEXT")).Replace("[PARAM]", grp.Name)

			' set songs
			Dim isThereASong As Boolean = False
			If grp.SongURL1 <> Nothing AndAlso grp.SongURL1 <> "" Then
				hlSong1.Attributes.Add("href", "#song")
				hlSong1.Attributes.Add("onclick", Me.constructMusicURL(grp.SongURL1))
				hlSong1.Text = grp.SongURL1
				If grp.SongURLName1 <> Nothing AndAlso grp.SongURLName1 <> "" Then
					hlSong1.Text = grp.SongURLName1
				End If
				isThereASong = True
			Else
				hlSong1.Visible = False
			End If

			If grp.SongURL2 <> Nothing AndAlso grp.SongURL2 <> "" Then
				hlSong2.Attributes.Add("href", "#song")
				hlSong2.Attributes.Add("onclick", Me.constructMusicURL(grp.SongURL2))
				hlSong2.Text = grp.SongURL2
				If grp.SongURLName2 <> Nothing AndAlso grp.SongURLName2 <> "" Then
					hlSong2.Text = grp.SongURLName2
				End If
				isThereASong = True
			Else
				hlSong2.Visible = False
			End If

			If grp.SongURL3 <> Nothing AndAlso grp.SongURL3 <> "" Then
				hlSong3.Attributes.Add("href", "#song")
				hlSong3.Attributes.Add("onclick", Me.constructMusicURL(grp.SongURL3))
				hlSong3.Text = grp.SongURL3
				If grp.SongURLName3 <> Nothing AndAlso grp.SongURLName3 <> "" Then
					hlSong3.Text = grp.SongURLName3
				End If
				isThereASong = True
			Else
				hlSong3.Visible = False
			End If

			If grp.ClipURL <> Nothing AndAlso grp.ClipURL <> "" Then
				hlClip.Attributes.Add("href", "#song")
				hlClip.Attributes.Add("onclick", Me.constructMusicURL(grp.ClipURL))
				hlClip.Text = grp.ClipURL
				If grp.ClipURLName <> Nothing AndAlso grp.ClipURLName <> "" Then
					hlClip.Text = grp.ClipURLName
				End If
				isThereASong = True
			Else
				hlClip.Visible = False
			End If

			trSongs.Visible = isThereASong

			' set events
			grpEvents = GroupEvents.LoadGroupEvents(grpID, Constants.MAX_GRID_EVENTS_ON_GROUP_PAGE)

			hlEditProfile.NavigateUrl = "../" + Constants.EDIT_GROUP_BASIC + "?" + Constants.GROUP_PARAM + "=" + grp.ID
			hlEditPhoto.NavigateUrl = "../" + Constants.UPLOAD_GROUP_PHOTO + "?" + Constants.GROUP_PARAM + "=" + grp.ID
			hlEditMembers.NavigateUrl = "../" + Constants.SEE_ALL_MEMBERS + "?" + Constants.GROUP_PARAM + "=" + grpID + "&action=" + Constants.SEE_ALL_FRIENDS_EDIT_ACTION
			hlEditMembersComments.NavigateUrl = "../" + Constants.GROUP_COMMENTS_PAGE + "?usr=" + usr.ID + "&" + Constants.GROUP_PARAM + "=" + grp.ID + "&action=" + Constants.FRIENDS_COMMENTS_EDIT_ACTION
			hlEditPhoto2.NavigateUrl = "../" + Constants.UPLOAD_GROUP_PHOTO + "?" + Constants.GROUP_PARAM + "=" + grp.ID
			hlEditDetails.NavigateUrl = "../" + Constants.EDIT_GROUP_BASIC + "?" + Constants.GROUP_PARAM + "=" + grp.ID
			hlSeeAllMembers.NavigateUrl = "../" + Constants.SEE_ALL_MEMBERS + "?" + Constants.GROUP_PARAM + "=" + grpID
			hlBackToGroup.NavigateUrl = "../" + Constants.GROUP_WELCOME + "?" + Constants.GROUP_PARAM + "=" + grpID
			hlBackToGroup.Text = (Me.GetPageConstText(htPageConstants, "CONST_GroupBackLink_TEXT")).Replace("[PARAM]", grp.Name)

			'set moderator
			hlModerator.Text = Users.GetUserByID(grp.Uid).Name
			hlModerator.NavigateUrl = "../" + Constants.MEMBERS + "?id=" + grp.Uid

			'set group image
			Dim grpPicture As GroupPicture = DirectCast(grp.DefaultPicture, GroupPicture)
			If grpPicture <> Nothing Then
				imgGroupPicture.ImageUrl = Pictures.GetPictureLargeThumbnailSrcFullURL(grpPicture, "../")
			Else
				imgGroupPicture.ImageUrl = "../images/default_thumbnail.gif"
			End If
			imgGroupPicture.ToolTip = grp.Name
			' set group photos count
			Dim pics As ArrayList = grp.GetPictures()
			hlPhotosInAlbum.Text = "<font class='bulletin_orange'>" + pics.Count.ToString() + "</font>" + " Photo"
			If pics.Count <> 1 Then
				hlPhotosInAlbum.Text += "s"
			End If
			hlPhotosInAlbum.Text += " in Album"

			hlPhotosInAlbum.NavigateUrl = "../" + Constants.VIEW_GROUP_PHOTOS + "?" + Constants.GROUP_PARAM + "=" + grp.ID

			hlEditComments.NavigateUrl = "../" + Constants.GROUP_COMMENTS_PAGE + "?usr=" + usr.ID + "&" + Constants.GROUP_PARAM + "=" + grp.ID + "&action=" + Constants.FRIENDS_COMMENTS_EDIT_ACTION

			Dim NewComments As ArrayList = grp.NewComments
			Dim ApprovedComments As ArrayList = grp.Comments

			If NewComments.Count = 0 AndAlso ApprovedComments.Count = 0 Then
				dgMessages.Visible = False
				lblNoComments.Visible = True
				hlEditComments.Visible = False
			End If

			If grpEvents.Count > 0 Then
				' set Events
				For Each result As GroupEvent In grpEvents
					Dim months As String() = Constants.ARR_MONTHS
					Dim lblEventDate As New Label()
					Dim lblEventPlace As New Label()
					Dim hlEvent As New HyperLink()
					lblEventDate.Text = result.DateTimeEvent.ToString("dddd, MMMM dd h:mm tt")

					hlEvent.NavigateUrl = "../" + Constants.VIEW_GROUP_EVENTS + "?" + Constants.GROUP_PARAM + "=" + result.GroupID
					hlEvent.Text = result.Venue
					If (result.ZipCode <> Nothing) AndAlso (result.ZipCode.Trim() <> String.Empty) Then
						lblEventPlace.Text = result.ZipCode + ", " + result.City
					Else
						lblEventPlace.Text = result.City
					End If

					addTableRow(lblEventDate, hlEvent, lblEventPlace)
				Next

				hlViewAllEvents.NavigateUrl = "../" + Constants.VIEW_GROUP_EVENTS + "?" + Constants.GROUP_PARAM + "=" + grpID
			Else
				trEventsShowsHead.Visible = False
				trEventsShows.Visible = False
			End If

			' Init count of users waiting to join the group if the group is private
			Dim grpPendingMembers As GroupsPendingUsers = grp.PendingMembers
			If grpPendingMembers.Count > 0 Then
				hlViewConfirmation.NavigateUrl = "../" + Constants.VIEW_AWAITING_CONFIRMATION + "?" + Constants.GROUP_PARAM + "=" + grp.ID
				hlViewConfirmation.Text = (Me.GetPageConstText(htPageConstants, "CONST_VIewAwaitingConfirm_TEXT")).Replace("[PARAM]", grpPendingMembers.Count.ToString())
				hlViewConfirmation.Visible = True
			End If

			' init group details table

			' set Category
			Dim lblCategory As New Label()
			Dim hlCategoryValue As New HyperLink()
			lblCategory.Text = Me.GetPageConstText(htPageConstants, "CONST_Category_TEXT")
			lblCategory.Font.Bold = True
			hlCategoryValue.Text = Constants.CATEGORIES.GetCategoryByID(grp.CatID).Name
			hlCategoryValue.NavigateUrl = "../" + Constants.CATEGORY_GROUPS + "?" + Constants.CATEGORY_PARAM + "=" + grp.CatID

			addTableRow(lblCategory, hlCategoryValue)

			' set Group Type
			Dim lblGroupTypeValue As New Label()
			Dim lblGroupType As New Label()
			lblGroupType.Text = Me.GetPageConstText(htPageConstants, "CONST_GroupType_TEXT")
			lblGroupType.Font.Bold = True
			lblGroupTypeValue.Text = IIf(grp.PublicGroup,Me.GetPageConstText(htPageConstants, "CONST_Public_TEXT"),Me.GetPageConstText(htPageConstants, "CONST_Private_TEXT"))

			addTableRow(lblGroupType, lblGroupTypeValue)

			' Clear session for the new searches
			Session(Constants.ssnAdvGroupSearchFilter) = Nothing

			' set Country
			Dim hlCountryValue As New HyperLink()
			Dim lblCountry As New Label()
			lblCountry.Text = Me.GetPageConstText(htPageConstants, "CONST_Country_TEXT")
			lblCountry.Font.Bold = True
			If grp.CountryID = -1 Then
				hlCountryValue.Text = ""
			Else
				hlCountryValue.Text = Constants.COUNTRIES.GetCountryByID(grp.CountryID).Name
				hlCountryValue.NavigateUrl = "../" + Constants.GROUP_SEARCH_RESULTS + "?" + Constants.COUNTRY_PARAM + "=" + grp.CountryID
			End If

			addTableRow(lblCountry, hlCountryValue)

			'set City
			Dim lblCity As New Label()
			Dim hlCityValue As New HyperLink()
			lblCity.Text = Me.GetPageConstText(htPageConstants, "CONST_City_TEXT")
			lblCity.Font.Bold = True
			If grp.City <> Nothing Then
				hlCityValue.Text = grp.City
				hlCityValue.NavigateUrl = "../" + Constants.GROUP_SEARCH_RESULTS + "?" + Constants.CITY_PARAM + "=" + grp.City
			End If

			addTableRow(lblCity, hlCityValue)

			'set Activities
			If grp.Activities <> "" AndAlso grp.Activities <> Nothing Then
				Dim lblActivities As New Label()
				Dim lblActivitiesValue As New Label()
				lblActivities.Text = Me.GetPageConstText(htPageConstants, "CONST_Activities_TEXT")
				lblActivities.Font.Bold = True
				'if( grp.Activities != null && grp.Activities.Length > 0)
				'{
				'string[] arrActivities = grp.Activities.Split(',', ';');
				'for(int i=0; i<arrActivities.Length; i++)
				'	lblActivitiesValue.Text += "<a href='"+ Constants.GROUP_SEARCH_RESULTS + "?"+ Constants.KEYWORD_PARAM +"=" + arrActivities[i].Trim() + "'>"+ arrActivities[i].Trim() +"</a>, ";
				'if( lblActivitiesValue.Text.Length > 0)
				'	lblActivitiesValue.Text = lblActivitiesValue.Text.Substring(0, lblActivitiesValue.Text.Length-2);
				'}
				lblActivitiesValue.Text = grp.Activities

				addTableRow(lblActivities, lblActivitiesValue)
			End If

			' set Contacts
			If grp.Contacts <> "" AndAlso grp.Contacts <> Nothing Then
				Dim lblContacts As New Label()
				Dim lblContactsValue As New Label()
				lblContacts.Text = Me.GetPageConstText(htPageConstants, "CONST_Contacts_TEXT")
				lblContacts.Font.Bold = True
				'if( grp.Contacts != null && grp.Contacts.Length > 0)
				'{
				'string[] arrContacts = grp.Contacts.Split(',', ';');
				'for(int i=0; i<arrContacts.Length; i++)
				'	lblContactsValue.Text += "<a href='"+ Constants.GROUP_SEARCH_RESULTS + "?"+ Constants.KEYWORD_PARAM +"=" + arrContacts[i].Trim() + "'>"+ arrContacts[i].Trim() +"</a>, ";
				'if( lblContactsValue.Text.Length > 0)
				'	lblContactsValue.Text = lblContactsValue.Text.Substring(0, lblContactsValue.Text.Length-2);
				'}
				lblContactsValue.Text = grp.Contacts

				addTableRow(lblContacts, lblContactsValue)
			End If

			'set Charity
			If grp.Charity <> "" AndAlso grp.Charity <> Nothing Then
				Dim lblCharityValue As New Label()
				Dim lblCharity As New Label()
				lblCharity.Text = Me.GetPageConstText(htPageConstants, "CONST_Charity_TEXT")
				lblCharity.Font.Bold = True
				'if( grp.Charity != null && grp.Charity.Length > 0)
				'{
				'string[] arrCharity = grp.Charity.Split(',', ';');
				'for(int i=0; i<arrCharity.Length; i++)
				'	lblCharityValue.Text += "<a href='"+ Constants.GROUP_SEARCH_RESULTS + "?"+ Constants.KEYWORD_PARAM +"=" + arrCharity[i].Trim() + "'>"+ arrCharity[i].Trim() +"</a>, ";
				'if( lblCharityValue.Text.Length > 0)
				'	lblCharityValue.Text = lblCharityValue.Text.Substring(0, lblCharityValue.Text.Length-2);
				'}
				lblCharityValue.Text = grp.Charity

				addTableRow(lblCharity, lblCharityValue)
			End If

			' set Image
			If grp.ImageURL <> "" AndAlso grp.ImageURL <> Nothing Then
				Dim lblFavImage As New Label()
				Dim hlFavImageURL As New HyperLink()
				lblFavImage.Text = Me.GetPageConstText(htPageConstants, "CONST_SeeImage_TEXT")
				lblFavImage.Font.Bold = True

				If grp.ImageURLName <> Nothing AndAlso grp.ImageURLName <> "" Then
					hlFavImageURL.Text = grp.ImageURLName
				End If

				hlFavImageURL.Attributes.Add("href", "#")
				hlFavImageURL.Attributes.Add("onclick", Me.constructImageURL(grp.ImageURL))

				addTableRow(lblFavImage, hlFavImageURL)
			End If

			' set Clip
			If grp.ClipURL <> "" AndAlso grp.ClipURL <> Nothing Then
				Dim lblClip As New Label()
				Dim hlClipURL As New HyperLink()
				lblClip.Text = Me.GetPageConstText(htPageConstants, "CONST_Watch_TEXT")
				lblClip.Font.Bold = True

				If grp.ClipURLName <> Nothing AndAlso grp.ClipURLName <> "" Then
					hlClipURL.Text = grp.ClipURLName
				End If

				hlClipURL.Attributes.Add("href", "#")
				hlClipURL.Attributes.Add("onclick", Me.constructMusicURL(grp.ClipURL))

				addTableRow(lblClip, hlClipURL)
			End If

			' list Bands details if any
			Dim grpBands As GroupBands = GroupBands.GetGroupBandsByGroupID(grpID)
			If grpBands <> Nothing Then
				' set bands members
				If grpBands.Members <> Nothing AndAlso grpBands.Members.Length > 0 Then
					Dim lblGroupBandMembers As New Label()
					Dim lblGroupBandMembersValue As New Label()
					lblGroupBandMembers.Font.Bold = True

					lblGroupBandMembers.Text = Me.GetPageConstText(htPageConstants, "CONST_BandMembers_TEXT")
					lblGroupBandMembersValue.Text = grpBands.Members

					addTableRow(lblGroupBandMembers, lblGroupBandMembersValue)
				End If

				' set bands influences
				If grpBands.Influences <> Nothing AndAlso grpBands.Influences.Length > 0 Then
					Dim lblGroupBandInfluences As New Label()
					Dim lblGroupBandInfluencesValue As New Label()
					lblGroupBandInfluences.Font.Bold = True

					lblGroupBandInfluences.Text = Me.GetPageConstText(htPageConstants, "CONST_Influences_TEXT")
					lblGroupBandInfluencesValue.Text = grpBands.Influences

					addTableRow(lblGroupBandInfluences, lblGroupBandInfluencesValue)
				End If

				' set bands sounds like
				If grpBands.SoundsLike <> Nothing AndAlso grpBands.SoundsLike.Length > 0 Then
					Dim lblGroupBandSoundsLike As New Label()
					Dim lblGroupBandSoundsLikeValue As New Label()
					lblGroupBandSoundsLike.Font.Bold = True

					lblGroupBandSoundsLike.Text = Me.GetPageConstText(htPageConstants, "CONST_Soundslike_TEXT")
					lblGroupBandSoundsLikeValue.Text = grpBands.SoundsLike

					addTableRow(lblGroupBandSoundsLike, lblGroupBandSoundsLikeValue)
				End If

				' set bands genres
				Dim tmpGenre As String = ""
				If grpBands.Genre1 > 0 Then
					tmpGenre = Constants.GENRE.GetGroupGenreByID(grpBands.Genre1).Name + ", "
				End If

				If grpBands.Genre2 > 0 Then
					tmpGenre += Constants.GENRE.GetGroupGenreByID(grpBands.Genre2).Name + ", "
				End If

				If grpBands.Genre3 > 0 Then
					tmpGenre += Constants.GENRE.GetGroupGenreByID(grpBands.Genre3).Name + ", "
				End If

				If tmpGenre.Length > 0 Then
					Dim lblGroupBandGenre As New Label()
					Dim lblGroupBandGenreValue As New Label()
					lblGroupBandGenre.Font.Bold = True

					lblGroupBandGenre.Text = Me.GetPageConstText(htPageConstants, "CONST_Genre_TEXT")
					lblGroupBandGenreValue.Text = tmpGenre.Substring(0, tmpGenre.Length - 2)

					addTableRow(lblGroupBandGenre, lblGroupBandGenreValue)
				End If

				' set bands site URL
				If grpBands.SiteURL <> Nothing AndAlso grpBands.SiteURL.Length > 0 Then
					Dim lblGroupBandSiteURL As New Label()
					Dim hlGroupBandSiteURLValue As New HyperLink()
					lblGroupBandSiteURL.Font.Bold = True

					lblGroupBandSiteURL.Text = Me.GetPageConstText(htPageConstants, "CONST_BandWebsite_TEXT")
					hlGroupBandSiteURLValue.Text = getBeginning(HttpUtility.HtmlEncode(grpBands.SiteURL), Constants.MAX_LINK_LENGTH)
					hlGroupBandSiteURLValue.NavigateUrl = grpBands.SiteURL
					hlGroupBandSiteURLValue.Target = "_blank"

					addTableRow(lblGroupBandSiteURL, hlGroupBandSiteURLValue)
				End If

				' set bands record label
				If grpBands.RecordLabel <> Nothing AndAlso grpBands.RecordLabel.Length > 0 AndAlso grpBands.RecordLabel <> Constants.LABEL_DEFAULT_VALUE Then
					Dim lblGroupBandRecordLabel As New Label()
					Dim lblGroupBandRecordLabelValue As New Label()
					lblGroupBandRecordLabel.Font.Bold = True

					lblGroupBandRecordLabel.Text = Me.GetPageConstText(htPageConstants, "CONST_RecordLabel_TEXT")
					lblGroupBandRecordLabelValue.Text = grpBands.RecordLabel

					addTableRow(lblGroupBandRecordLabel, lblGroupBandRecordLabelValue)
				End If

				' set bands label type
				If grpBands.LabelType > 0 Then
					Dim lblGroupBandLabelType As New Label()
					Dim lblGroupBandLabelTypeValue As New Label()
					lblGroupBandLabelType.Font.Bold = True

					lblGroupBandLabelType.Text = Me.GetPageConstText(htPageConstants, "CONST_LabelType_TEXT")
					lblGroupBandLabelTypeValue.Text = Constants.LABELTYPES.GetLabelTypeByID(grpBands.LabelType).Name

					addTableRow(lblGroupBandLabelType, lblGroupBandLabelTypeValue)
				End If
			End If

			If Not IsPostBack Then
				BindList()
				BindGrid()
			End If
		End Sub

		' add row to details table
		Private Sub addTableRow(ByVal ctlName As Control, ByVal ctlValue As Control)
			Dim tr As New TableRow()
			Dim td1 As New TableCell()
			Dim td2 As New TableCell()

			td1.Controls.Add(ctlName)
			td2.Controls.Add(ctlValue)
			td1.Width = 100
			td2.Width = 210
			td1.CssClass = "clear"
			td2.CssClass = "clear"
			tr.Cells.Add(td1)
			tr.Cells.Add(td2)

			tblGroupDetails.Rows.Add(tr)
		End Sub

		Private Sub addTableRow(ByVal ctlName1 As Control, ByVal ctlName2 As Control, ByVal ctlName3 As Control)
			Dim tr As New TableRow()
			Dim td1 As New TableCell()
			Dim td2 As New TableCell()
			Dim td3 As New TableCell()

			td1.Controls.Add(ctlName1)
			td2.Controls.Add(ctlName2)
			td3.Controls.Add(ctlName3)
			td1.Wrap = False
			td1.CssClass = "clear"
			td2.CssClass = "clear"
			td3.CssClass = "clear"
			td1.Width = Unit.Percentage(30)
			td2.Width = Unit.Percentage(45)
			td3.Width = Unit.Percentage(25)
			tr.Cells.Add(td1)
			tr.Cells.Add(td2)
			tr.Cells.Add(td3)

			tblGroupEvents.Rows.Add(tr)
		End Sub

		Public Function CreateDataSource() As ICollection
			Dim usr As User = LoggedUser
			Dim grp As Group = Groups.GetGroupByID(grpID)
			Dim startIndex As Integer = 0
			Dim endIndex As Integer = startIndex + Constants.MAX_PICTURES_ON_WELCOME_PAGE

			Dim i As Integer
			Dim dt As New DataTable()
			Dim dr As DataRow

			dt.Columns.Add(New DataColumn("ImageURL", GetType(String)))
			dt.Columns.Add(New DataColumn("Name", GetType(String)))
			dt.Columns.Add(New DataColumn("OnlineImg", GetType(String)))
			dt.Columns.Add(New DataColumn("MemberID", GetType(String)))
			dt.Columns.Add(New DataColumn("MemberFullName", GetType(String)))

			blankImagesCount = 0
			Dim imagesOnLastRow As Integer = 0
			Dim t As Integer = 0
			Dim counter As Integer = 0
			Dim UsersCount As Integer
			Dim LoggedUsersList As ArrayList = Common.Utils.GetLoggedUsersIDs()

			UsersCount = grp.Members.Count
			Dim temp As UserPicture
			endIndex = Math.Min(endIndex, UsersCount)
			t = (endIndex - startIndex)
			Math.DivRem(t, Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE, imagesOnLastRow)
			counter = 0

			For Each gm As BO.GroupMember In grp.Members
				If counter >= startIndex AndAlso counter < endIndex Then
					dr = dt.NewRow()
					temp = gm.User.DefaultPicture
					If temp <> Nothing Then
						dr(0) = Pictures.GetPictureSrcFullURL(temp, True, "../")
					Else
						dr(0) = "../images/default_thumbnail.gif"
					End If
					dr(1) = getBeginning(HttpUtility.HtmlEncode(gm.User.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
					If LoggedUsersList.Contains(gm.User.ID) Then
						dr(2) = "../images/online_status.gif"
					Else
						dr(2) = "../images/spacer.gif"
					End If
					dr(3) = gm.User.ID
					dr(4) = gm.User.Name
					dt.Rows.Add(dr)
				End If
				System.Math.Max(System.Threading.Interlocked.Increment(counter),counter - 1)
			Next

			If imagesOnLastRow <> 0 Then
				blankImagesCount = Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE - imagesOnLastRow
				i = imagesOnLastRow
				While i < Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE
					dr = dt.NewRow()
					dr(0) = "../images/spacer.gif"
					dr(1) = ""
					dr(2) = "../images/spacer.gif"
					dt.Rows.Add(dr)
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While
			End If

			Dim dv As New DataView(dt)
			Return dv
		End Function

		Public Sub BindList()
			Dim itemsCount As Integer
			Dim blankImageIndex As Integer
			Dim i As Integer

			dlAllMembers.DataSource = CreateDataSource()
			dlAllMembers.DataBind()

			itemsCount = dlAllMembers.Items.Count
			blankImageIndex = itemsCount - blankImagesCount
			i = 0
			i = blankImageIndex
			While i < itemsCount
				(DirectCast(dlAllMembers.Items(i).FindControl("lbName"), System.Web.UI.WebControls.LinkButton)).CssClass = "empty_image"
				(DirectCast(dlAllMembers.Items(i).FindControl("imgMember"), System.Web.UI.WebControls.Image)).CssClass = "empty_image"
				System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
			End While
		End Sub

		Protected Function CreateDataSourceForGrid() As ICollection
			Dim startIndex As Integer = 0
			Dim endIndex As Integer = startIndex + Constants.COMMENTS_ON_PROFILE_PAGE
			Dim grp As Group = Groups.GetGroupByID(grpID)
			Dim dt As New DataTable()
			Dim curCommentDate As DateTime

			Dim LoggedUsersList As ArrayList = Common.Utils.GetLoggedUsersIDs()

			' List group's comments

			Dim dr As DataRow
			dt.Columns.Add(New DataColumn("SenderID", GetType(Integer)))
			dt.Columns.Add(New DataColumn("SenderName", GetType(String)))
			dt.Columns.Add(New DataColumn("SenderImageURL", GetType(String)))
			dt.Columns.Add(New DataColumn("OnlineImg", GetType(String)))
			dt.Columns.Add(New DataColumn("MemberURL", GetType(String)))
			dt.Columns.Add(New DataColumn("Date", GetType(String)))
			dt.Columns.Add(New DataColumn("Time", GetType(String)))
			dt.Columns.Add(New DataColumn("Comment", GetType(String)))
			dt.Columns.Add(New DataColumn("CommentID", GetType(String)))
			dt.Columns.Add(New DataColumn("ButtonsVisibility", GetType(Boolean)))
			dt.Columns.Add(New DataColumn("RejectText", GetType(String)))
			dt.Columns.Add(New DataColumn("SenderNameFull", GetType(String)))
			dt.Columns.Add(New DataColumn("RemoveVisibility", GetType(Boolean)))

			Dim newCommentList As ArrayList, approvedCommentList As ArrayList, allComments As ArrayList
			allComments = New ArrayList()

			newCommentList = grp.NewComments
			approvedCommentList = grp.Comments
			If grp.Uid = LoggedUser.ID Then
				allComments = newCommentList
			End If
			Dim i As Integer = 0
			While i < approvedCommentList.Count
				allComments.Add(approvedCommentList(i))
				System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
			End While

			endIndex = allComments.Count
			endIndex = startIndex + Math.Min(allComments.Count, Constants.COMMENTS_ON_PROFILE_PAGE)
			Dim temp As UserPicture
			Dim curSender As User
			Dim grpComment As GroupComment
			Dim i As Integer = startIndex
			While i < endIndex
				' List user's NEW comments
				dr = dt.NewRow()
				grpComment = DirectCast(allComments(i), GroupComment)
				curCommentDate = grpComment.[Date]
				curSender = Users.GetUserByID(grpComment.PostedByUserID)

				dr(0) = grpComment.PostedByUserID
				dr(1) = getBeginning(HttpUtility.HtmlEncode(curSender.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
				dr(11) = curSender.Name
				temp = curSender.DefaultPicture
				If temp <> Nothing Then
					dr(2) = Pictures.GetPictureSrcFullURL(temp, True, "../")
				Else
					dr(2) = Constants.DEFAULT_THUMBNAIL_IMAGE_URL
				End If
				If LoggedUsersList.Contains(curSender.ID) Then
					dr(3) = "../images/online_status.gif"
				Else
					dr(3) = "../images/spacer.gif"
				End If
				dr(4) = "../" + Constants.MEMBERS + "?id=" + grpComment.PostedByUserID
				dr(5) = curCommentDate.DayOfWeek + ", " + Constants.MONTHS(curCommentDate.Month - 1) + " " + curCommentDate.Day + ", " + curCommentDate.Year
				dr(6) = curCommentDate.ToShortTimeString()
				dr(7) = grpComment.Comment
				dr(8) = grpComment.ID
				If grpComment.CommentStatus = GroupComment.Status.ucsNew Then
					dr(9) = True
					dr(10) = "Reject"
				Else
					dr(9) = False
					'if(action == Constants.FRIENDS_COMMENTS_EDIT_ACTION)
					dr(10) = "Remove"
				End If
				If grp.Uid = LoggedUser.ID OrElse LoggedUser.ID = grpComment.PostedByUserID Then
					dr(12) = True
				Else
					dr(12) = False
				End If

				dt.Rows.Add(dr)
				System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
			End While

			Dim dv As New DataView(dt)
			Return dv
		End Function
		Protected Sub BindGrid()
			dgMessages.DataSource = CreateDataSourceForGrid()
			dgMessages.DataBind()
		End Sub

		Private Sub dgMessages_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
			Dim grp As Group = Groups.GetGroupByID(grpID)
			Dim lbPushed As LinkButton = DirectCast(e.CommandSource, LinkButton)
			Dim cmd As String = e.CommandName

			Select Case cmd
				Case "Reject"
					' reject/remove comment
					grp.RemoveComment(Convert.ToInt32(e.CommandArgument))
					Exit Select
				Case "Approve"
					'approve comment
					grp.ApproveComment(Convert.ToInt32(e.CommandArgument))
					Exit Select
			End Select
			BindGrid()
		End Sub

		Private Sub dlAllMembers_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs)
			Dim src As Object = e.CommandSource
			Dim srcType As String = src.[GetType]().ToString()
			Dim cmd As String = e.CommandName
			Dim arg As String = ""
			If srcType.Equals("System.Web.UI.WebControls.ImageButton") Then
				arg = (DirectCast(src, ImageButton)).CommandArgument
			Else
				arg = (DirectCast(src, LinkButton)).CommandArgument
			End If
			Select Case cmd
				Case "MemberRedirect"
					Response.Redirect(Constants.MEMBERS + "?id=" + e.CommandArgument)
					Exit Select
			End Select
		End Sub

		Protected Sub lbEditMembersWithImage_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			Response.Redirect(Constants.SEE_ALL_MEMBERS + "?" + Constants.GROUP_PARAM + "=" + grpID + "&action=" + Constants.SEE_ALL_FRIENDS_EDIT_ACTION)
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			AddHandler Me.dlAllMembers.ItemCommand, AddressOf Me.dlAllMembers_ItemCommand
			AddHandler Me.dgMessages.ItemCommand, AddressOf Me.dgMessages_ItemCommand

		End Sub
#End Region

		Protected Sub lbAddMembers_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			Response.Redirect(Constants.SEND_MESSAGE + "?" + Constants.ACTION_PARAM + "=" + Constants.MESSAGE_FORWARD_A_GROUP_ACTION + "&" + Constants.FORWARD_A_GROUP_PARAM + "=" + grpID)
		End Sub

		====================
		' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
		Public ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
			Get
				Return Migrated_Form1
			End Get
		End Property
		'set { Migrated_Form1 = value; }
	End Class
End Namespace






